﻿namespace UnityEditor
{
    using System;
    using System.Runtime.CompilerServices;
    using UnityEngine;

    internal class VerticalGrid
    {
        private int m_Columns = 1;
        private float m_Height;
        private float m_HorizontalSpacing;
        private int m_Rows;

        public Rect CalcRect(int itemIdx, float yOffset)
        {
            float num = Mathf.Floor((float) (itemIdx / this.columns));
            float num2 = itemIdx - (num * this.columns);
            return new Rect((this.leftMargin + (this.horizontalSpacing * 0.5f)) + (num2 * (this.itemSize.x + this.horizontalSpacing)), ((num * (this.itemSize.y + this.verticalSpacing)) + this.topMargin) + yOffset, this.itemSize.x, this.itemSize.y);
        }

        public int GetMaxVisibleItems(float height)
        {
            int num = (int) Mathf.Ceil(((height - this.topMargin) - this.bottomMargin) / (this.itemSize.y + this.verticalSpacing));
            return (num * this.columns);
        }

        public void InitNumRowsAndColumns(int itemCount, int maxNumRows)
        {
            this.m_Columns = (int) Mathf.Floor(((this.fixedWidth - this.leftMargin) - this.rightMargin) / (this.itemSize.x + this.minHorizontalSpacing));
            this.m_Columns = Mathf.Max(this.m_Columns, 1);
            this.m_HorizontalSpacing = (this.fixedWidth - (((this.m_Columns * this.itemSize.x) + this.leftMargin) + this.rightMargin)) / ((float) this.m_Columns);
            this.m_Rows = Mathf.Min(maxNumRows, (int) Mathf.Ceil(((float) itemCount) / ((float) this.m_Columns)));
            this.m_Height = (((this.m_Rows * (this.itemSize.y + this.verticalSpacing)) - this.verticalSpacing) + this.topMargin) + this.bottomMargin;
        }

        public float bottomMargin { get; set; }

        public int columns
        {
            get
            {
                return this.m_Columns;
            }
        }

        public float fixedWidth { get; set; }

        public float height
        {
            get
            {
                return this.m_Height;
            }
        }

        public float horizontalSpacing
        {
            get
            {
                return this.m_HorizontalSpacing;
            }
        }

        public Vector2 itemSize { get; set; }

        public float leftMargin { get; set; }

        public float minHorizontalSpacing { get; set; }

        public float rightMargin { get; set; }

        public int rows
        {
            get
            {
                return this.m_Rows;
            }
        }

        public float topMargin { get; set; }

        public float verticalSpacing { get; set; }
    }
}

